# -*- coding: utf-8 -*-
# @Date    : 2017-05-26 17:26:28
# @Author  : fancy (fancy@thecover.co)

from time import ctime
from twisted.internet import protocol, reactor

PORT = 8888

class TSServerProtocol(protocol.Protocol):

    def connectionMade(self):
        clnt = self.clnt = self.transport.getPeer().host
        print '...connected from: %s' % clnt

    def dataReceived(self, data):
        self.transport.write('[{a}] {b}'.format(a=ctime(), b=data))

factory = protocol.Factory()
factory.protocol = TSServerProtocol
print 'waiting for connection...'
reactor.listenTCP(PORT, factory)
reactor.run()
